<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/reset.css">
    <script src="../js/cookie.js"></script>
    <script src="../js/tool.js"></script>
    <style>
        .input-group {
            margin-top: 10px;
        }

        .right {
            font-size: 12px;
            color: green;
        }

        .error {
            font-size: 12px;
            color: red;
        }
    </style>
</head>

<body>
    <form action="" onsubmit="return false" autocomplete="off">
        <div class="input-group">
            <labal>用户名:</labal>
            <input type="text" class="account" name="account" placeholder="用户名/手机号/邮箱">
            <span class="account_tips"></span>
        </div>
        <div class="input-group">
            <labal>密&emsp;码:</labal>
            <input type="password" class="pwd" name="pwd">
            <span class="pwd_tips"></span>
        </div>
        <div class="input-group">
            <input type="submit" class="submit" value="登录">
            <input type="reset" class="reset" value="取消">
        </div>
    </form>
</body>

<script>

    var form = document.getElementsByTagName("form")[0];
    var { account: accountInp, pwd: pwdInp, phone: phoneInp, email: emailInp } = document.getElementsByTagName("form")[0];
    console.log(accountInp, pwdInp, phoneInp, emailInp);

    var subBtn = document.getElementsByClassName("submit")[0];

    subBtn.onclick = function () {
        // 用户输入的 用户名和密码
        var account = accountInp.value;
        var pwd = pwdInp.value;
        if (account && pwd) {
            var xhr = new XMLHttpRequest();

            xhr.open("post", "http://43.138.81.225/demo/php/login_account.php", true);

            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
            xhr.send(`account=${account}&pwd=${pwd}`);

            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    var result = xhr.responseText;
                    result = JSON.parse(result);
                    console.log(result);
                    var { status, message, user } = result;
                    if (status) {
                        setCookie("lgc", user, 31 * 24 * 60 * 60);

                        var url = urlParamsParse();
                        var { ReturnUrl } = url;
                        if (ReturnUrl) { //其他页面条过来
                            location.href = ReturnUrl;
                        } else {
                            location.href = "./index.html";
                        }

                    } else {
                        alert(message);
                    }

                }
            }


        }
    }








</script>

</html>